package com.zhenlong01.zhentest.controller;

import com.zhenlong01.zhentest.WebSocketServer;
import com.zhenlong01.zhentest.dao.BaoXiuDanDao;
import com.zhenlong01.zhentest.dao.BaoXiuManDao;
import com.zhenlong01.zhentest.dao.RepairManDao;
import com.zhenlong01.zhentest.entity.BaoXiuDan;
import com.zhenlong01.zhentest.entity.BaoXiuMan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author Administrator
 * @date 2019-08-28 22:13
 */
@RestController
public class BaoXiuManController {
    @Autowired
    BaoXiuManDao baoXiuManDao;

    @GetMapping("/find_all_baoxiuman")
    public Page<BaoXiuMan> findAll(int p, int size){
        Sort sort = new Sort(Sort.Direction.DESC,"id");
        PageRequest pr =  PageRequest.of(p-1,size,sort);
        //Pageable pageable = new PageRequest(p - 1, size);
        return baoXiuManDao.findAll(pr);
    }

    @GetMapping("/bxm_shenhe")
    public boolean bxm_shenhe(int bxm_id,int status,@RequestParam(value="rejectMsg",
            defaultValue="") String rejectMsg){
        try{
            BaoXiuMan bxm = baoXiuManDao.findById(bxm_id).get();
            bxm.setStatus(status);
            if(rejectMsg.length()>0){
                bxm.setRejectMsg(rejectMsg);
                //发短信 发邮件 发微信通知
            }
            baoXiuManDao.save(bxm);
        }catch (Exception ex){
            return false;
        }
        return true;
    }

    @PostMapping("/baoxian_man_bind")
    public BaoXiuMan baoxian_man_bind(@RequestBody  BaoXiuMan baoXiuMan){
        return baoXiuManDao.save(baoXiuMan);
    }

    @GetMapping("/find_baoxiuman_byopenid")
    public BaoXiuMan find_baoxiuman_byopenid(String openid){

        return baoXiuManDao.findByOpenid(openid);
    }
}